package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.LawsRegulationsAddDTO;
import org.jsola.hr.dto.LawsRegulationsUpdateDTO;
import org.jsola.hr.entity.LawsRegulationsDO;
import org.jsola.hr.query.LawsRegulationsQuery;
import org.jsola.hr.service.ILawsRegulationsService;
import org.jsola.hr.vo.LawsRegulationsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 卫人云-政策法规
 *
 * @author zhr
 */
@Component
public class LawsRegulationsTestHelper extends BaseTestHelper {
    
    @Autowired
    private ILawsRegulationsService lawsRegulationsService;

    /**
     * 生成add测试数据
     * @return LawsRegulationsAddDTO
     */
    public LawsRegulationsAddDTO getLawsRegulationsAddDTO(){
        LawsRegulationsAddDTO lawsRegulationsAddDTO = new LawsRegulationsAddDTO();
        lawsRegulationsAddDTO.setTitle(getRandomValue("varchar",50));
        lawsRegulationsAddDTO.setTypeCode(getRandomValue("varchar",32));
        lawsRegulationsAddDTO.setCoverImg(getRandomValue("varchar",500));
        lawsRegulationsAddDTO.setDetailHeaderImg(getRandomValue("varchar",500));
        lawsRegulationsAddDTO.setContent(getRandomValue("mediumtext",2147483647));
        lawsRegulationsAddDTO.setContentHasStyle(getRandomValue("mediumtext",2147483647));
        lawsRegulationsAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        lawsRegulationsAddDTO.setIsTop(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return lawsRegulationsAddDTO;
    }


    /**
     * 生成update测试数据
     * @return LawsRegulationsUpdateDTO
     */
    public LawsRegulationsUpdateDTO getLawsRegulationsUpdateDTO(LawsRegulationsVO lawsRegulationsVO){
        return lawsRegulationsService.selectDOById(lawsRegulationsVO.getId(), SITE_ID).to(LawsRegulationsUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return LawsRegulationsQuery
     */
    public LawsRegulationsQuery getLawsRegulationsQuery() {
        LawsRegulationsQuery lawsRegulationsQuery = new LawsRegulationsQuery();
        List<LawsRegulationsDO> lawsRegulationsDOList = lawsRegulationsService.list(new LawsRegulationsDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(lawsRegulationsDOList)) {
            LawsRegulationsDO lawsRegulationsDO = lawsRegulationsDOList.get(0);
            lawsRegulationsQuery = lawsRegulationsDO.to(LawsRegulationsQuery.class);
        }
        return lawsRegulationsQuery;
    }

    /**
     * 保存示例
     * @return LawsRegulationsVO
     */
    public LawsRegulationsVO saveLawsRegulationsExample(){
        LawsRegulationsAddDTO addDTO = this.getLawsRegulationsAddDTO();
        LawsRegulationsVO lawsRegulationsVO = lawsRegulationsService.save(addDTO,buildTokenUser());
        return lawsRegulationsVO;
    }


}

